package com.ljf.tijian.mapper;

import com.ljf.tijian.dto.CalendarResponseDto;
import com.ljf.tijian.dto.OrdersDto;
import com.ljf.tijian.dto.OrdersMapperDto;
import com.ljf.tijian.dto.ReportDto;
import com.ljf.tijian.pojo.Orders;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrdersMapper {
    int deleteByPrimaryKey(String orderId);

    int insert(Orders record);

    int insertSelective(Orders record);

    Orders selectByPrimaryKey(String orderId);

    int updateByPrimaryKeySelective(Orders record);

    int updateByPrimaryKey(Orders record);

    List<CalendarResponseDto> listOrdersAppointmentNumber(List<OrdersMapperDto> ordersMapperDtos);

    @Select("select orderId, orderDate, userId, hpId, smId, state from orders where userId=#{userId} and orderDate=date(#{orderDate})")
    Orders selectByUserIdAndOrderDate(Orders orders);

    @Select("select orderId, orderDate, userId, hpId, smId, state from orders where userId=#{userId} and state=#{state}")
    List<Orders> selectByUserIdAndStateList(Orders orders);

    @Select("select o.orderId, o.orderDate, o.userId, o.hpId, o.smId, s.name, o.state" +
            "\n" +
            "from orders o,setmeal s " +
            "where o.smId = s.smId"
    )
    List<OrdersDto> selectAllOrdersForSmId();

    @Select("select o.orderId, o.orderDate, o.userId, o.hpId, o.smId, h.name, o.state" +
            "\n" +
            "from orders o,hospital h " +
            "where o.hpId = h.hpId"
    )
    List<OrdersDto> selectAllOrdersForHpId();

    @Select("select o.orderId, o.orderDate, h.name " +
            "from users u,orders o,hospital h " +
            "where u.userId = o.userId and o.hpId = h.hpId and o.state = 3 and u.userId = #{userId} ")
    List<ReportDto> selectAllReportsByUserId(Long userId);
}